package com.ht.activiti.controller;

import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 验证跨域问题
 * @author zhangfc
 * @date 2021/11/4 9:29
 */
@RestController
@RequestMapping("/user")
public class UserController {
    //    @RequiresPermissions("user:list")
    @GetMapping("/show")
    public String showUser() {
        return "这是学生信息";
    }

    @GetMapping("/listByUserId")
    //@CrossOrigin //解决跨域
    public List<Map<String, Object>> listByUserId(HttpServletResponse response) {
        List<Map<String, Object>> userList = new ArrayList<>();

        Map<String, Object> map = new HashMap<>();
        map.put("name", "张三");
        userList.add(map);

        Map<String, Object> map1 = new HashMap<>();
        map1.put("name", "李四");
        userList.add(map1);
//        response.setHeader("Access-Control-Allow-Origin", "*");
//        response.setHeader("Cache-Control", "no-cache");
        return userList;
    }
}
